package ucas.pin.web.repositories;

import ucas.pin.web.domain.MedMaterial;
import ucas.pin.web.domain.Prescription;

import java.util.Collection;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

/**
 * @author pdtyreus
 * @author Mark Angrish
 */
@RepositoryRestResource(collectionResourceRel = "medMaterials", path = "medMaterials")
public interface MedMaterialRepository extends PagingAndSortingRepository<MedMaterial, Long> {
	
	@Query("MATCH (m:MedMaterial)<-[r_c:Consist]-(p:Prescription) where m.name = {0} return m,r_c,p")
	Collection<MedMaterial> getGraphByName(String name);
	
	@Query("MATCH (m:MedMaterial) where m.name = {0} return m")
	Collection<MedMaterial> getEntityByName(String name);
	
	@Query("MATCH (m:MedMaterial) where m.name =~ {0} return m")
	Collection<MedMaterial> findMedMaterialByNameLike(String name);
}
